home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / screen / saver.frm < prev    next >
Text File  |  1994-11-28  |  7KB  |  239 lines

  1. VERSION 2.00
  2. Begin Form frmSaver 
  3.    BackColor       =   &H00000000&
  4.    BorderStyle     =   0  'None
  5.    ClientHeight    =   2940
  6.    ClientLeft      =   285
  7.    ClientTop       =   3150
  8.    ClientWidth     =   6990
  9.    ControlBox      =   0   'False
  10.    Height          =   3345
  11.    Icon            =   SAVER.FRX:0000
  12.    KeyPreview      =   -1  'True
  13.    Left            =   225
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "Form1"
  16.    MaxButton       =   0   'False
  17.    MinButton       =   0   'False
  18.    ScaleHeight     =   2940
  19.    ScaleWidth      =   6990
  20.    Top             =   2805
  21.    Width           =   7110
  22.    Begin PictureClip pclRedTop 
  23.       Cols            =   6
  24.       Location        =   "5940,2745,60,960"
  25.       Picture         =   SAVER.FRX:0302
  26.       Rows            =   3
  27.    End
  28.    Begin Image imgRedTop 
  29.       Height          =   855
  30.       Left            =   0
  31.       Top             =   0
  32.       Visible         =   0   'False
  33.       Width           =   915
  34.    End
  35. End
  36. Option Explicit
  37. Dim FirstTime As Integer
  38. Dim PicIndex As Integer
  39.  
  40. Dim y1 As Integer
  41. Dim x1 As Integer
  42.  
  43. Dim incY1 As Integer
  44. Dim incX1 As Integer
  45.  
  46. Dim picWidth As Integer
  47. Dim picHeight As Integer
  48.  
  49. Dim LastX As Integer
  50. Dim LastY As Integer
  51.  
  52. '
  53. ' Invoked upon an event that could end the screen saver
  54. ' ie. KeyDown, MouseDown, MouseMove
  55. '
  56. Sub EndScreenSaver ()
  57.     
  58. Dim i As Integer
  59.  
  60.     On Error GoTo Fred
  61.     frmSaver.Enabled = False
  62.     Call ShowMouse
  63.     
  64.     If PWprotected Then
  65.         ' Load up the password form
  66.         ValidPassword = False
  67.         frmEnterPass.Show 1
  68.         ' Decide what to do
  69.         Select Case ValidPassword
  70.             Case 1 ' Valid
  71.                 End
  72.             Case 2 ' Canceled
  73.                 ' Reset this form to be TopMost
  74.                 SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  75.                 ' Set the Form to be System Modal (Ouch!)
  76.                 i = SetSysModalWindow(hWnd)
  77.                 Call HideMouse
  78.                 frmSaver.Enabled = True
  79.                 Exit Sub
  80.             Case 3 ' Invalid
  81.                 frmError.Show 1
  82.                 ' Reset this form to be TopMost
  83.                 SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  84.                 ' Set the Form to be System Modal (Ouch!)
  85.                 i = SetSysModalWindow(hWnd)
  86.                 Call HideMouse
  87.                 frmSaver.Enabled = True
  88.                 Exit Sub
  89.         End Select
  90.     End If
  91.     ' if not password protected then stop the Screen Saver
  92.     End
  93. Fred:
  94.     frmSaver.Enabled = True
  95.     ' Reset this form to be TopMost
  96.     SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  97.     ' Set the Form to be System Modal (Ouch!)
  98.     i = SetSysModalWindow(hWnd)
  99.     Call HideMouse
  100.     Exit Sub
  101.  
  102. End Sub
  103.  
  104. Sub Form_Activate ()
  105.  
  106.     ' The first time the form is activated after it has loaded
  107.     If FirstTime Then
  108.         FirstTime = False
  109.         ' Call the Screen Saver Initialization routine
  110.         Call InitRedTop
  111.         ' Call the Main Screen Saver Loop
  112.         Call RedTop
  113.     End If
  114.  
  115. End Sub
  116.  
  117. Sub Form_KeyDown (KeyCode As Integer, Shift As Integer)
  118.     
  119.     ' If any key is pressed then
  120.     ' Set coords to 0 so as not to catch a
  121.     ' mouse move over the password form
  122.     LastX = 0
  123.     LastY = 0
  124.     EndScreenSaver
  125.  
  126. End Sub
  127.  
  128. Sub Form_Load ()
  129.     
  130. Dim i As Integer
  131.  
  132.     FirstTime = True
  133.     'Maximize the Window (Which is all black) - It is a screen saver after all!
  134.     WindowState = 2
  135.     ' Set the form to be TopMost
  136.     SetWindowPos Me.hWnd, -1, 0, 0, 0, 0, 3
  137.     ' Set the Form to be System Modal (Ouch!)
  138.     i = SetSysModalWindow(hWnd)
  139.  
  140. End Sub
  141.  
  142. Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  143.     
  144.     ' If either mouse Button is pressed then
  145.     ' Set coords to 0 so as not to catch a
  146.     ' mouse move over the password form
  147.     LastX = 0
  148.     LastY = 0
  149.     EndScreenSaver
  150.  
  151. End Sub
  152.  
  153. Sub Form_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  154.  
  155.     ' Only Check for mouse move is the user has
  156.     ' asked for this check in the Setup form.
  157.     
  158.     If MouseMove = 0 Then
  159.         If LastX = 0 Or LastY = 0 Then
  160.             ' first time round or return from EndScreenSaver
  161.             LastX = X
  162.             LastY = Y
  163.         End If
  164.         ' If This position is not near the last position recorded
  165.         If Abs(LastX - X) > 2 * Screen.TwipsPerPixelX Or Abs(LastY - Y) > 2 * Screen.TwipsPerPixelY Then
  166.             ' Set coords to 0 so as not to catch a
  167.             ' mouse move over the password form
  168.             LastX = 0
  169.             LastY = 0
  170.             EndScreenSaver
  171.         Else
  172.             ' Remember the position for the next MouseMove event
  173.             LastX = X
  174.             LastY = Y
  175.         End If
  176.     End If
  177.  
  178. End Sub
  179.  
  180. '
  181. ' Initialize the Screen Saver
  182. '
  183. Sub InitRedTop ()
  184.         
  185.         ' Set the First Graphic from the PicClip
  186.         PicIndex = 0
  187.         imgRedTop.Picture = pclRedTop.GraphicCell(PicIndex)
  188.         ' Set the width & height of the picture box
  189.         picWidth = 66 * Screen.TwipsPerPixelX
  190.         picHeight = 61 * Screen.TwipsPerPixelY
  191.         ' Set the Start coordinates
  192.         x1 = 0
  193.         y1 = 0
  194.         ' Set the increments in both x and y directions
  195.         incX1 = 25
  196.         incY1 = 20
  197.         ' Make the image visible
  198.         imgRedTop.Visible = True
  199.  
  200. End Sub
  201.  
  202. '
  203. ' The Screen Saver Main Loop
  204. '
  205. ' This loop only ends on the termination of the Screen Saver
  206. '
  207. Sub RedTop ()
  208.  
  209. Dim i As Integer
  210.     
  211.     While True ' forever!
  212.         ' Get next image from PicClip
  213.         PicIndex = PicIndex + 1
  214.         If PicIndex = 18 Then PicIndex = 0
  215.         imgRedTop.Picture = pclRedTop.GraphicCell(PicIndex)
  216.         ' Get next position
  217.         y1 = y1 + incY1
  218.         x1 = x1 + incX1
  219.         ' Check for edges of screen and if necessary change direction
  220.         If y1 >= Screen.Height - picHeight Or y1 <= 0 Then
  221.             incY1 = -1 * incY1
  222.         End If
  223.         If x1 >= Screen.Width - picWidth Or x1 <= 0 Then
  224.             incX1 = -1 * incX1
  225.         End If
  226.         ' move the image
  227.         imgRedTop.Move x1, y1
  228.         ' Make sure everything is painted properly
  229.         DoEvents
  230.         ' a rather crude way of slowing the display down
  231.         ' without impacting on the system as a whole
  232.         For i = 0 To (500 - SpinSpeed)
  233.             DoEvents
  234.         Next i
  235.     Wend
  236.  
  237. End Sub
  238.  
  239.